<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <parent></parent>
    </div>

    <template id="parent">
        <div>
            {{msg}}
            <child @change="getVal"></child>
        </div>
    </template>

    <template id="child">
        <div>
            <button @click="add()">增加1</button>
            <button @click="less()">减少1</button>
        </div>
    </template>
</body>
</html>
<script src="js/vue.min.js"></script>
<script>
    var app=new Vue({
        el:"#app",
        data:{

        },
        components:{
            "parent":{
                template:"#parent",
                data:function(){
                    return {
                        msg:0
                    }
                },
                methods:{
                    getVal:function(va){
                        console.log(va);
                        this.msg=va;
                    }
                },
                components:{
                    "child":{
                        template:"#child",
                        data:function(){
                            return {
                                val:0
                            }
                        },
                        methods:{
                            add:function(){
                                this.$emit("change",++this.val);
                            },
                            less:function(){
                                this.$emit("change",--this.val);
                            }
                        }
                    }
                }
            }
        }
    });
</script>